/*
 * @Author: qinruiguang
 * @LastEditors: qinruiguang
 * @Date: 2021-04-02 11:04:57
 * @LastEditTime: 2021-08-06 18:02:22
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
import "./assets/public"

import {
  Loading,
  Message
} from 'element-ui'
// http请求拦截器
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$axios = axios;
//axios拦截设置
// axios.defaults.baseURL = "https://w3cjs.cn/"
axios.defaults.timeout = 50000;
let loadingInstance
axios.interceptors.request.use(config => {
  // 在发送请求之前做些什么
  // loadingInstance = Loading.service({
  //     lock: true,
  //     text: 'Loading',
  //     spinner: 'el-icon-loading',
  //     background: 'rgba(0, 0, 0, 0.7)'
  // });
  let user = localStorage.getItem("user")
  let obj = ""
  if (user) {
    obj = JSON.stringify(user)[0]
  }
  config.headers.common['Advices'] = obj.token ? obj.token : "null";
  return config;
}, error => {
  // 对请求错误做些什么
  return Promise.reject(error);
});
//http响应拦截器
axios.interceptors.response.use(data => { // 响应成功关闭loading
  // loadingInstance.close();
  return data
}, error => {
  // loadingInstance.close(); 
  Message.error({
    message: '加载失败'
  })
  return Promise.reject(error)
})
Vue.prototype.hint = function (i, e) {
  if (i === 0) {
    this.$message({
      message: "" + e,
      type: "success"
    });
  }
  if (i === 1) {
    this.$message({
      message: "" + e,
      type: "warning"
    });
  }
  if (i === 2) {
    this.$message.error("" + e);
  }
}
Vue.prototype.jm = (e) => {
  if (e === "") return ""
  return new Buffer(e, 'base64').toString()
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
